package cn.lsnu.heritage.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.lsnu.heritage.common.Constants;
import cn.lsnu.heritage.common.Result;
import cn.lsnu.heritage.exception.CustomerException;
import cn.lsnu.heritage.model.dto.IcHeritageDTO;
import cn.lsnu.heritage.model.vo.IcHeritageVO;
import cn.lsnu.heritage.service.IcHeritageService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("heritage")
public class IcHeritageController {
    @Resource
    private IcHeritageService icHeritageService;



    //根据分类id查询非遗列表
    @GetMapping("category/{id}")
    public Result<List<IcHeritageDTO>> queryHeritageListByCategoryId(@PathVariable("id") Integer id){
        if (id < 0 || id == null || id > 10){
            throw new CustomerException(Constants.ERROR_PARAM,"参数不合法");
        }
        return Result.success(icHeritageService.queryHeritageListByCategoryId(id));
    }


    //根据条件查询非遗集合
    @PostMapping("queryHeritageList")
    public Result<Page<IcHeritageDTO>> queryHeritageList(@RequestBody IcHeritageVO heritageVO){
        if (BeanUtil.isEmpty(heritageVO)){
            throw new CustomerException(Constants.ERROR_PARAM,"请求参数不能为空");
        }
        return Result.success(icHeritageService.queryHeritageList(heritageVO));
    }

    /*查询热门非遗集合*/
    @GetMapping("/queryHotHeritageList")
    public Result<List<IcHeritageDTO>> queryHotHeritageList(){
        return Result.success(icHeritageService.queryHotHeritageList());
    }

    /*根据id查询非遗信息*/
    @GetMapping("/queryHeritageById")
    public Result<IcHeritageDTO> queryHeritageById(Integer id) {

        return Result.success(icHeritageService.queryHeritageById(id));
    }


}
